/*
 * JFrameAdminCat.java
 *
 * Created on 2 de junio de 2006, 1:26
 */

package fmap.gui;

import fmap.DatosCompartidos;
import fmap.dao.CatDao;
import fmap.gui.actionListener.ListenerJFrameAdminCat;
import fmap.utils.FormUtils;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JList;
import javax.swing.JTextField;

/**
 *
 * @author  javi
 */
public class JFrameAdminCat extends javax.swing.JFrame
{
    
    /** Creates new form JFrameAdminCat */
    public JFrameAdminCat ()
    {
        initComponents ();
        
        Vector vCats = new CatDao ().selectCats ();
        
        if( vCats.size () > 0 )
        {
            listCatMapF.setListData ( vCats );
        }
        
        ListenerJFrameAdminCat listener = new ListenerJFrameAdminCat ( this );
        
        buttonSaveCatMapF.addActionListener ( listener );
        buttonDeleteCatMapF.addActionListener ( listener );
        
        listCatMapF.addListSelectionListener ( listener );
        
        
        FormUtils.centra (this);
        addWindowListener ( new ListenerWindow () );
        setVisible (true);
    }
    
    
    public JTextField getTextFCatMapF ()
    { return textFCatMapF; }
    public JList getListCatMapF ()
    { return listCatMapF; }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        jScrollPane1 = new javax.swing.JScrollPane();
        listCatMapF = new javax.swing.JList();
        buttonSaveCatMapF = new javax.swing.JButton();
        textFCatMapF = new javax.swing.JTextField();
        buttonDeleteCatMapF = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Fmap - Categorias");
        setAlwaysOnTop(true);
        jScrollPane1.setViewportView(listCatMapF);

        buttonSaveCatMapF.setFont(new java.awt.Font("Dialog", 0, 12));
        buttonSaveCatMapF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fmap/img/save.png")));
        buttonSaveCatMapF.setText("Guardar");
        buttonSaveCatMapF.setActionCommand("guardar");
        buttonSaveCatMapF.setMargin(new java.awt.Insets(2, 2, 2, 2));
        buttonSaveCatMapF.setPreferredSize(new java.awt.Dimension(83, 20));

        buttonDeleteCatMapF.setFont(new java.awt.Font("Dialog", 0, 12));
        buttonDeleteCatMapF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fmap/img/cancel.png")));
        buttonDeleteCatMapF.setText("Eliminar");
        buttonDeleteCatMapF.setActionCommand("eliminar");
        buttonDeleteCatMapF.setMargin(new java.awt.Insets(2, 2, 2, 2));

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel1.setText("Categorias de volumenes de ficheros");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addContainerGap(221, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(textFCatMapF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 325, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(buttonSaveCatMapF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                    .add(buttonDeleteCatMapF, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .add(2, 2, 2)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(buttonDeleteCatMapF)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                .add(19, 19, 19)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(textFCatMapF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                    .add(buttonSaveCatMapF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonDeleteCatMapF;
    private javax.swing.JButton buttonSaveCatMapF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JList listCatMapF;
    private javax.swing.JTextField textFCatMapF;
    // End of variables declaration//GEN-END:variables
    
    public class ListenerWindow implements WindowListener
    {
        // Constructor que guarda la referencia al objeto JFrame
        public ListenerWindow ()
        {}
        
        public void windowClosed ( WindowEvent evt )
        {
            // Cuando cerramos esta ventana => actualizamos el combo del formulario de nuevo mapF
            if( DatosCompartidos.getACat ().length > 0 )
            {
                DatosCompartidos.getJFrameNewMapF ().getComboBoxCatMapF ().setModel ( new DefaultComboBoxModel ( DatosCompartidos.getACat () ) );
            }
        }
        
        public void windowIconified ( WindowEvent evt )
        {}
        public void windowOpened ( WindowEvent evt )
        {}
        public void windowClosing ( WindowEvent evt )
        {}
        public void windowDeiconified ( WindowEvent evt )
        {}
        public void windowActivated ( WindowEvent evt )
        {}
        public void windowDeactivated ( WindowEvent evt )
        {}
        
    }
}
